package com.elvin.wx.controller;

import com.elvin.wx.util.IotToken;
import com.elvin.wx.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname TokenController
 * @Description token相关
 * @Date 2022/1/10 下午10:51
 * @Created by yuankeyan
 */
@Controller
@RestController
@Log4j2
@Api("token管理")
public class TokenController {

    @ApiOperation(value = "获取token")
    @PostMapping("/getToken")
    public Result<Object> assembleToken(@RequestParam("resourceName") String resourceName, @RequestParam("et") String expirationTime, @RequestParam("accessKey") String accessKey) {
        Result<Object> result = new Result<>();
        try {
            String token = IotToken.assembleToken(resourceName, expirationTime, accessKey);
            result.success(token);
        } catch (Exception e) {
            log.debug(e.getMessage());
            result.fail(null, e.getMessage());
        }
        return result;
    }
}
